package com.imooc.web.async;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

/**
 * Created by zghgchao 2018/4/19 20:44
 * 消息队列
 */
@Component
public class MockQueue {
    private Logger logger = LoggerFactory.getLogger(this.getClass());

    private String placeOrder;//下单消息
    private String compleOrder;//订单完成消息

    public String getPlaceOrder() {
        return placeOrder;
    }

    public void setPlaceOrder(String placeOrder) throws Exception{
        //另开线程，相当于 应用二
        new Thread(()->{
            logger.info("接到订单请求: "+placeOrder);
            try {
                Thread.sleep(1000);//处理下单业务逻辑
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            this.compleOrder = placeOrder;//将接收到的 下单消息 传给 completeOrder
            logger.info("下单请求处理完成："+ placeOrder);
        }).start();


    }

    public String getCompleOrder() {
        return compleOrder;
    }

    public void setCompleOrder(String compleOrder) {
        this.compleOrder = compleOrder;
    }
}
